package lambda;

import org.junit.Test;

import java.util.function.Consumer;

/**
 * @description: Lamdba详细演示
 * @author: apple
 * @date:  2022/1/2 11:02 上午
 * @version 1.0
 **/
public class LambdaTest1 {

    interface Table {
        void id();
    }
    interface Table2 {
        void set(Object obj);
    }
    interface Table3 {
        Object get();
    }
    interface Table4 {
        Object set(Object obj);
    }

    // 无参无返回值
    @Test
    public void test1() {

        Table t = new Table() {
            @Override
            public void id() {
                System.out.println("11");
            }

        };
        t.id();

        Table t2 = ()->{
            System.out.println("22");
        };
        t2.id();
    }


    // 有参无返回值
    @Test
    public void test2() {
        Table2 t = (Object obj) -> {
            System.out.println(obj);
        };
        t.set(99);

        System.out.println("-----");
        Consumer<? super String> con = (Object obj) -> {
            System.out.println(obj);
        };
        con.accept("abc");
    }

    // 无参有返回值
    @Test
    public void test3() {
        Table3 t = () -> {

            return 16>>2;
        };

        final Object o = t.get();
        System.out.println(o);

    }

    // 有参有返回值
    @Test
    public void test4() {
        Table4 t = (obj) -> {
            return obj+"test";
        };

        final Object hello_ = t.set("hello ");
        System.out.println(hello_);


    }
}
